import { FC } from "react"

import { ShortcutOptionsType } from "@/components/common/timeSelectionShortcuts/types"
import { useLocale } from "@/locales"
import { rangeBeginning, rangeCurrentMonth, rangePastNDays, rangePastNMonth, rangeToday, rangeYesterday } from "@/utils"

import TimeRange from "../timeRange"

const LoginTimeRange: FC<any> = ({ setFieldValue, defaultValue, isAllowedAllTime = false }) => {
	const { formatMessage } = useLocale()

	const defaultshortcuts: ShortcutOptionsType[] = [
		{
			label: formatMessage({ id: "common.utils.today" }),
			value: rangeToday()
		},
		{
			label: formatMessage({ id: "common.utils.yesterday" }),
			value: rangeYesterday()
		},
		{
			label: formatMessage({ id: "common.utils.last_n_days" }, { n: 7 }),
			value: rangePastNDays(7)
		},
		{
			label: formatMessage({ id: "common.utils.last_n_days" }, { n: 14 }),
			value: rangePastNDays(14)
		},
		{
			label: formatMessage({ id: "common.utils.last_n_days" }, { n: 30 }),
			value: rangePastNDays(30)
		},
		{
			label: formatMessage({ id: "common.utils.last_month" }),
			value: rangePastNMonth(1)
		},
		{
			label: formatMessage({ id: "common.utils.this_month" }),
			value: rangeCurrentMonth()
		},
		{
			label: formatMessage({ id: "common.utils.month3_recent" }),
			value: rangePastNDays(90)
		}
	]

	if (isAllowedAllTime) {
		defaultshortcuts.push({
			label: formatMessage({ id: "common.utils.select_all_range" }),
			value: rangeBeginning()
		})
	}

	return (
		<TimeRange
			presets={defaultshortcuts}
			setFieldValue={setFieldValue}
			label="label.member.login_time"
			fieldName="loginTime"
			startFieldName="loginStartTime"
			endFieldName="loginEndTime"
			format="YYYY-MM-DD HH:mm:ss"
			showTime={{ format: "HH:mm:ss" }}
			defaultValue={defaultValue}
		/>
	)
}

export default LoginTimeRange
